package com.peng.mybatis.type;

import java.lang.reflect.Type;
import java.util.HashMap;
import java.util.Map;

public class TypeHandlerRegistry {

    private final Map<JdbcType, TypeHandler<?>> JDBC_TYPE_HANDLER_MAP = new HashMap<>();

    private final Map<Type, Map<JdbcType, TypeHandler<?>>> TYPE_HANDLER_MAP = new HashMap<>();

    private final Map<Class<?>, TypeHandler<?>> ALL_TYPE_HANDLER_MAP = new HashMap<>();


    private void register(Type javaType, JdbcType jdbcType, TypeHandler<?> typeHandler) {
        if (jdbcType != null) {
            Map<JdbcType, TypeHandler<?>> map = TYPE_HANDLER_MAP.computeIfAbsent(javaType, k -> new HashMap<>());
            map.put(jdbcType, typeHandler);
        }
        ALL_TYPE_HANDLER_MAP.put(typeHandler.getClass(), typeHandler);
    }

}
